package com.zj.juc.study.lockSupport;

import java.util.concurrent.TimeUnit;

/**
 * @author zj
 * @version 1.0.0
 * @ClassName LockSupportDemo
 * @Description 正常的wait,notify等待唤醒机制
 * @createTime 2024年12月26日 22:37
 */
public class ObjectWaitNotifyNormalDemo {
    public static void main(String[] args) {
        Object lock = new Object();
        new Thread(()->{
            synchronized (lock){
                System.out.println(Thread.currentThread().getName()+"\t"+".....come in");
                try {
                    lock.wait();//交出锁，阻塞
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+".....被唤醒");
            }
        },"t1").start();

        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        new Thread(()->{
            synchronized (lock){
                lock.notify();
                System.out.println("发出通知");
            }
        },"t2").start();
    }
}
